/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

using ll = long long;

constexpr int maxn = (1 << 19), mod = 998244353;

int a[maxn + 5];
ll fac[maxn + 5];
bool sum[maxn * 4 + 10];

void add(int cur, int l, int r, int pos) {
  if (l == r) {
    sum[cur] = true;
    return;
  }
  int mid = (l + r) >> 1;
  int ls = cur << 1, rs = cur << 1 | 1;
  if (pos <= mid) {
    add(ls, l, mid, pos);
  } else {
    add(rs, mid + 1, r, pos);
  }
  sum[cur] = sum[ls] | sum[rs];
}

void dele(int cur, int l, int r, int pos) {
  if (l == r) {
    sum[cur] = false;
    return;
  }
  int mid = (l + r) >> 1;
  int ls = cur << 1, rs = cur << 1 | 1;
  if (pos <= mid) {
    dele(ls, l, mid, pos);
  } else {
    dele(rs, mid + 1, r, pos);
  }
  sum[cur] = sum[ls] | sum[rs];
}

bool query(int cur, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return sum[cur];
  }
  bool res = 0;
  int mid = (l + r) >> 1;
  int ls = cur << 1, rs = cur << 1 | 1;
  if (L <= mid) {
    res |= query(ls, l, mid, L, R);
  }
  if (R > mid) {
    res |= query(rs, mid + 1, r, L, R);
  }
  return res;
}

int main() {
  int k;
  cin >> k;
  int n = 1 << k;
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = fac[i - 1] * i % mod;
  }
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x != -1) {
      a[i] = x;
    }
  }
  ll ans = 1;
  for (int i = k; i >= 1; --i) {
    int blk = 1 << (k - i + 1);
    int cnt = (1 << (i - 1));
    for (int j = (1 << (i - 1)) + 1; j <= 1 << i; ++j) {
      if (a[j]) {
        int tmp = (a[j] + blk - 1) / blk;
        if (query(1, 1, n, (tmp - 1) * blk + 1, tmp * blk)) {
          ans = 0;
        }
        add(1, 1, n, a[j]);
        cnt--;
      }
    }
    ans = ans * fac[cnt] % mod;
    ans = ans * (1 << cnt) % mod;
    for (int j = (1 << (i - 1)) + 1; j <= 1 << i; ++j) {
      if (a[j]) {
        dele(1, 1, n, a[j]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("E. Playoff Fixing.in", "r", stdin);
  freopen("E. Playoff Fixing.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
